import org.junit.Test;

public class LeetCode {

    class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }

    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
        int prev = 0;
        ListNode head = null;
        ListNode tail = null;
        while (l1 != null || l2 != null || prev != 0){
            int val1 = l1 != null ? l1.val : 0;
            int val2 = l2 != null ? l2.val : 0;
            int val = (val1 + val1) % 10 + prev;
            ListNode curNode = new ListNode(val);
            if(head == null){
                head = curNode;
                tail = curNode;
            } else {
                tail.next = curNode;
                tail = curNode;
            }
            prev = (val1 + val1) / 10;
            l1 = l1 != null ? l1.next : null;
            l2 = l2 != null ? l2.next : null;
        }
        return head;
    }

    @Test
    public void test1(){
        System.out.println("length:" + lengthOfLongestSubstring("pwwkew"));
    }

    public int lengthOfLongestSubstring(String s) {
        int maxLength = 0;
        for(int i = 0; i < s.length();i++){
            int curLength = 0;
            for(int j = i ; j < s.length(); j++){
                String frontStr = s.substring(i, j);
                String curStr = s.substring(j,j+1);
                System.out.println("frontStr = " + frontStr + ", curstr = " + curStr);
                if(existsChar(frontStr, curStr)){
                    break;
                }
                curLength++;
                if(curLength > maxLength){
                    maxLength = curLength;
                }
            }
        }

        return maxLength;
    }

    private boolean existsChar(String strs, String s){
        if(strs == null || s.length() == 0){
            return false;
        }
        if(s == null || s.length() == 0){
            return false;
        }
        return strs.contains(s);
    }



}
